package org.qloudgen.txn.dilithium.cluster.operator;

import org.qloudgen.txn.dilithium.cluster.beans.Cluster;

public abstract class AbstractClusterOperator implements IClusterOperator{

	private Cluster cluster;
	private String operatorType;
	
	public AbstractClusterOperator(Cluster cluster, String operatorType){
		this.setCluster(cluster);
		this.setOperatorType(operatorType);
	}
	
	public int handler(){
		
		// result
		// 0: success
		// -1 : failure
		int result = 0;
		
		if (operatorType.equals("start")){
			
			result = start(this.cluster);
			
		} else if (operatorType.equals("stop")){
			
			result = stop(this.cluster);
			
		} else if (operatorType.equals("delete")){
			
			result = delete(this.cluster.getClusterID());
			
		} 
		
		return result;
		
	}
	
	public String getOperatorType() {
		return operatorType;
	}

	public void setOperatorType(String operatorType) {
		this.operatorType = operatorType;
	}

	public Cluster getCluster() {
		return cluster;
	}

	public void setCluster(Cluster cluster) {
		this.cluster = cluster;
	}

}
